﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using GameBase;

namespace MilitaryPluginInterface
{
    public class MilitaryRank : VisibleGameEntity
    {
        private int _rank = 0;
        private int _maxRank;
        private List<Texture2D> _rankTextures = new List<Texture2D>();

        public int Rank
        {
            get { return _rank; }
            set
            {
                if (_rank >= 0 && _rank < _maxRank)
                    _rank = value;
            }
        }

        public MilitaryRank(string strTexture, int maxRank)
        {
            _maxRank = maxRank;
            Texture2D texture = GameBase.Constant.content.Load<Texture2D>(strTexture);
            int width = texture.Width/maxRank;
            int height = texture.Height;
            for (int i = 0; i < maxRank; i++)
            {
                _rankTextures.Add(GameBase.Texture2DHelper.createPartImage(GameBase.Constant.graphics, new Rectangle(i * width, 0, width, height), texture));
            }
            this.Size = new Vector2(width, height);
        }

        public int levelUp()
        {
            Rank++;
            return Rank;
        }

        public bool isMaxRank()
        {
            return _rank == _maxRank;
        }

        public override void draw(GameTime gameTime, SpriteBatch spriteBatch, Color color)
        {
            if (_rank == 0)
                return;
            spriteBatch.Draw(_rankTextures[_rank - 1], Position, Color.White);
        }
    }
}
